// app.js
let db = null
App({
  globalData:{

  },
  data:{
    service_url:"http://124.222.3.209:6464/Game/",
    is_play:1
  },
  onLaunch(){
    if(!wx.cloud){
      console.error('请使用2.2.3或以上的基础库以使用云能力')
    }
    else
    {
      wx.cloud.init({
        env:'cloud-base-8gj6ivf3af4be876',//env决定本小程序默认的云开发调用环境wx.cloud.xxx
        traceUser: true
      })
     
    }
    this.globalData = {}

    //获取用户openid
    this.getUserOpenId()

    
  },
  getUserOpenId:function()
  {

    var that=this
    //调用登录接口
    wx.login({
      success: function (res) {
      var code=res.code
        console.log(code)
        wx.request({
          url: that.data.service_url+'login/getOpenid', //改成你服务端的方法
          data: {
            code:code,
          },
          method:"POST",
          header:{
            "Content-Type": "application/x-www-form-urlencoded"
             },  
          success: function(res) {
            console.log(res)
          
            //如果是首次登录，会跳到授权页面
            if(res.data.code==0){
            console.log("首次访问")
            return false
            }
            if(res.data.code==1){



            }
            if(res.data.code==2)
            {
        wx.switchTab({
          url: '../../pages/tabs/home/home',
          success: function (res) {
            console.log('成功')
            }
         })

            }
      
            //更新用户微信信息 
            wx.setStorage({
              key:"openid",
              data:res.data.openid
            })
            wx.setStorage({
              key:"uid",
              data:res.data.uid
            })
        
          }
        })


      }
    })
 
  }

})